//还有一种更简单的方法，把1号点到其余各个点的距离（包括自己，到自己就是全部距离）用一个数组存起来，最后直接调用min(右边-左边，左边+全部-右边)即可！


#include <iostream>
#include <list>

using namespace std;

int main()
{
    int N;
    cin >> N;
    list<int> ls;
    for (int i = 0; i < N; ++i)
    {
        int t;
        cin >> t;
        ls.push_back(t);
    }

    int M;
    cin >> M;
    int l, r;
    for (int i = 0; i < M; ++i)
    {
        
        cin >> l >> r;
        if (l > r)
        {
            swap(l, r);
        }
        list<int>::iterator left = ls.begin();
        list<int>::iterator right = ls.begin();
        for (int j = 1; j < l; ++j)
        {
            ++left;
        }
        for (int j = 1; j < r; ++j)
        {
            ++right;
        }

        int ans1 = 0;
        for (list<int>::iterator it = left; it != right; ++it)
        {
            ans1 += *it;
        }
        int ans2 = 0;
        for (list<int>::iterator it = right; it != left; ++it)
        {
            if(it == ls.end())
            {
                continue;
            }
            ans2 += *it;
        }

        cout << min(ans1, ans2) << endl;
    }
}